
 <template>
 	<el-dialog title="" visible :show-close="false" :append-to-body="true" class="wrap" size="tiny">
 		<i class="el-icon-close close" @click="cancel" style="color: white;z-index:10;"></i>
	    <div class="bt">报损编辑</div>
 		<el-form label-width="100px" class="form">
 			<!--<el-form-item label="物品名称">
 				<el-input v-model="form.wpid" placeholder="请输入" class="select-block" v-if="false"  ></el-input>
			<el-input v-model="form.wpmc" placeholder="请输入物品名称" icon="add" class="input1" :readonly="true"></el-input>
			<el-button  @click="componentsShow('xzwp')">选择物品</el-button>
 			</el-form-item>-->
 			<el-form-item label="报损数量">
 				<el-input v-model="form.sl"  placeholder="请输入" class="select-block"></el-input>
 			</el-form-item>
 			<!--<el-form-item label="经手人名称">
 				<el-input v-model="form.jsrmc"  placeholder="请输入" class="select-block"></el-input>
 			</el-form-item>-->
 			<el-form-item label="报损人员">
 			<el-select v-model="form.bsr" class="select-block" >
                <el-option :label="v.zwm" :value="v.id+''" v-for="v in comboxlist"></el-option>
            </el-select>
 		</el-form-item>
      <el-form-item label="报损原因">
        <el-input v-model="form.bsyy" type="textarea" :rows="4" placeholder="请输入" class="select-block"></el-input>
      </el-form-item>
 		</el-form>
 		<el-button type="primary" class="submit" @click="submit">修改</el-button>

 		<Wpchooselist class="wpfl" @wpchoose="wpchooseed" @close="wpchoosecancel" v-if="showchoselist"  ></Wpchooselist>
		<Xzwplist v-if="portComponents.xzwp.toggle"  @close="componentsHide"  :data="portComponents.xzwp.data"></Xzwplist>

 	</el-dialog>
 </template>
 <script type="text/javascript">
 	import qs from 'qs'
// 	import Wpchooselist from '../wpfx/wpchooselist'
	import Xzwplist from './xzwp'

 	export default {
 		 components: { Xzwplist},
 		props: ['params'],
 		data() {
 			return {
 				showchoselist:false,
 				form: {
			           wpid :'',
			           sl :'',
			           bsyy :'',
			           jsrmc :'',
			           bsr :'',
 					   id:''
 				},
 				comboxlist:[],
 				portComponents: {
						xzwp : {
								type: 'xzwp',
								toggle: false,
								params: '',
								data: {}
						}
				},
 			}
 		},
 		created() {
  		 this.form.id = this.params.row.id;
          this.loadinfo();
          this.getcomboxlist();
 		},
 		methods: {
 			loadinfo(){
 				 var logininfo = JSON.parse(localStorage.logininfo) ;
         var params3 = qs.stringify({
               xxid:logininfo.xxid,
               yhid:logininfo.id,
               id:this.form.id
						});
 				 this.axios.post(this.$store.state.api+'wpbs/info',params3)
         .then( res =>  {
 							this.form=res.data.data
 					 }).catch(res => {
 						 this.$message.warning("服务器异常");
 			 				this.$emit('close', { type: 'info', cancel: true });
 					 })
 			},
 			getcomboxlist(){
					 var logininfo = JSON.parse(localStorage.logininfo) ;
				     this.searchLoading = true;
				     var params3 = qs.stringify({
							yhid: logininfo.id,
							xxid:logininfo.xxid
						});
				          this.axios.post(this.$store.state.api + 'ls/getzxls',params3)
						  .then( res => {
				              let data = res.data.data;
				              let list = data.list;
				              this.comboxlist=list;
				          }).catch( res => {
				              this.searchLoading = false;
				          })
				        },
 			 submit() {
 				//检测
 				this.$store.state.loading = true;
 				/*if(!this.form.id) {
 					this.$message.warning('请填写分类');
 					this.$store.state.loading = false;
 					return;
 				}*/
 				//装载数据
 				var logininfo = JSON.parse(localStorage.logininfo);
 				var params2 = qs.stringify({
 						id: this.form.id,
 						wpid: this.form.wpid,
 						sl: this.form.sl,
 						bsyy: this.form.bsyy,
 						jsr: this.form.jsr,
 						bsr: this.form.bsr,
 						yhid: logininfo.id,
 						xxid: logininfo.xxid
 					})
 				//执行
 				    this.axios.post(this.$store.state.api + 'wpbs/update',  params2 )
 						.then(res => {
 							if(res.data.code == 1) {
   							this.$message.success(res.data.msg);
 								this.$emit('close', { type: 'edit', cancel: false });
 								this.$store.state.loading = false;
 							} else {
   							this.$message.warning(res.data.msg);
 								this.$store.state.loading = false;
 							}
 						}).catch(res => {
 							this.$message.danger("服务器异常");
 							this.$store.state.loading = false;
 						})
 			},
 			wpchooseed(josndata){
				this.form.wpmc  = josndata.wpmc;
				this.form.wpid=josndata.wpid;
						this.showchoselist=false;
			},
			wpchoosecancel(){
						this.showchoselist=false;
			},	showwp(){
				this.showchoselist =true;
			},
 			cancel() {
 				this.$emit('close', { type: 'edit', cancel: true })
 			},
 			componentsShow (type,data) { //显示组件
						console.log(type,data)
						for ( let i in this.portComponents ) {
								if (type == this.portComponents[i].type) {
										console.log(this.portComponents[i])

										this.portComponents[i].toggle = true;
										this.portComponents[i].params = data;

										if (this.portComponents[i].data.type == 'single') {
												this.portComponents[i].data.index = data.row.id

										}else if(this.portComponents[i].data.type == 'multiple'){
												this.portComponents[i].data.index = this.multipleDelNum;

										}else{
												return;
										}
										return;
								}
						}

				},
				componentsHide (setting) { //关闭组件
					console.log()
						if(setting.data){
								this.form.wpmc = setting.data[0].mc
								this.form.wpid = setting.data[0].id
								// this.vje = setting.data[0].jg
								for ( let i in this.portComponents ) {
										if (setting.type == this.portComponents[i].type) {
												this.portComponents[i].toggle = false;
												if (this.portComponents[i].type == 'singleDelete') {
														this.dataList.splice(setting.index,1)
												}
												return;
										}
								}
						}else{
							for ( let i in this.portComponents ) {
			                    if (setting.type == this.portComponents[i].type) {
			                        this.portComponents[i].toggle = false;
			                        if (!setting.cancel) {

			                        }
			                        return;
			                    }
			                }
						}
						}
 		}
 	}
 </script>
 <style lang="less" scoped>
 	.wrap {
 		text-align: center;
 	}
 	.bt{
		position: absolute;
		width: 100%;
		height: 50px;
		margin: 0 auto;
		top: 0;
		left: 0;
		background: #50BFFF;
		color:white;
		text-align:left;
		line-height: 50px;
		font-size: 17px;
		padding-left: 15px;
	}
 	.form {
 		text-align: left;
 		margin-top: 10px;
 	}
 	.input {
             width: 300px;
             display: inline-block;
    }
    .input1 {
			width: 300px;
			display: inline-block;
		}
 	.select-block {
 		display: block;
 	}
 	.submit {
 		width: 120px;
 	}
 	.wpfl{
 			width: 218%;
 			height: 98%;
			background: #fff;
			position: absolute;
			top: 5px;
			left: -250px;
		}
 </style>
